package ink.ykb.demo.permission.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import ink.ykb.demo.config.CodeConstant;
import ink.ykb.demo.config.MessageUtil;
import ink.ykb.demo.config.ResponseMsg;
import ink.ykb.demo.permission.annotation.Function;
import ink.ykb.demo.permission.entity.DealerDepartment;
import ink.ykb.demo.permission.service.DealerDepartmentService;

/**
 * 经销商层级相关服务
 * 
 * @author mading
 *
 */
@RestController
@RequestMapping("/dealerDepartment")
public class DealerDepartmentController {

  @Autowired
  private DealerDepartmentService dealerDepartmentService;
  @Autowired
  private MessageUtil messageUtil;

  /**
   * 添加经销商层级
   * 
   * @param dealerDepartment
   */
  @Function("admin.dealerDepartment.add")
  @PostMapping(value = "/add")
  public ResponseMsg<String> add(DealerDepartment dealerDepartment) {
    dealerDepartmentService.add(dealerDepartment);
    return new ResponseMsg<>(CodeConstant.SUCCESS, messageUtil.getMsg(CodeConstant.SUCCESS));
  }

  /**
   * 更新经销商层级
   * 
   * @param dealerDepartment
   */
  @Function("admin.dealerDepartment.update")
  @PostMapping(value = "/update")
  public ResponseMsg<String> update(DealerDepartment dealerDepartment) {
    dealerDepartmentService.update(dealerDepartment);
    return new ResponseMsg<>(CodeConstant.SUCCESS, messageUtil.getMsg(CodeConstant.SUCCESS));
  }

  /**
   * 删除经销商层级
   * 
   * @param dealerDepartmentId
   */
  @Function("admin.dealerDepartment.delete")
  @PostMapping(value = "/delete")
  public ResponseMsg<String> delete(@RequestParam("dealerDepartmentId") Long dealerDepartmentId) {
    dealerDepartmentService.delete(dealerDepartmentId);
    return new ResponseMsg<>(CodeConstant.SUCCESS, messageUtil.getMsg(CodeConstant.SUCCESS));
  }

  /**
   * 查询经销商层级列表
   * 
   * @return
   */
  @Function("admin.dealerDepartment.list")
  @GetMapping(value = "/list")
  public ResponseMsg<List<DealerDepartment>> getDealerDepartmentList() {
    return new ResponseMsg<>(CodeConstant.SUCCESS, messageUtil.getMsg(CodeConstant.SUCCESS),
        dealerDepartmentService.getDealerDepartmentList());
  }

  /**
   * 获取经销商层级信息
   * 
   * @param dealerDepartmentId
   * @return
   */
  @Function("admin.dealerDepartment.get")
  @GetMapping(value = "/get")
  public ResponseMsg<DealerDepartment> getDealerDepartment(@RequestParam("dealerDepartmentId") Long dealerDepartmentId) {
    return new ResponseMsg<>(CodeConstant.SUCCESS, messageUtil.getMsg(CodeConstant.SUCCESS),
        dealerDepartmentService.getDealerDepartment(dealerDepartmentId));
  }
  
}
